import json
import yaml
import sys


def to_json(data):
    try:
        return json.loads(data)
    except Exception as e:
        print('data解析失败:', e)
        sys.exit(1)


def read_json(file):
    try:
        with open(file, 'r', encoding='utf-8') as f:
            return f.read()
    except Exception as e:
        print('文件读取失败:', e)
        sys.exit(1)


def to_yml_json(data):
    try:
        return yaml.full_load(data)
    except Exception as e:
        print('data解析失败:', e)
        sys.exit(1)


def read_yml(file):
    try:
        with open(file, 'r', encoding='utf-8') as f:
            return yaml.full_load(f)
    except Exception as e:
        print('文件读取失败:', e)
        sys.exit(1)
